#ifndef _HARDWARE_USART_H_
#define _HARDWARE_USART_H_

#include <avr/interrupt.h>
#include <avr/io.h>
#include "../../../bit/bit.h"

enum ParityHardwareUSART { DisabledParityHardwareUSART, ReservedParityHardwareUSART,
			   EvenParityHardwareUSART, OddParityHardwareUSART};

enum DataSizeHardwareUSART { Data_5BitsUSART, Data_6BitsUSART, Data_7BitsUSART, Data_8BitsUSART, Data_9BitsUSART};




typedef struct HARDWARE_USART_CONFIG
{
	unsigned char parity : 2;
	unsigned char size : 3;
	unsigned char sync : 1;
	unsigned char receiveInterrupt : 1;
	unsigned char sendInterrupt : 1;
	unsigned char emptyInterrupt : 1;
	unsigned char receiver : 1;
	unsigned char transmitter : 1;
	unsigned char multiProcessorCommunication : 1;
	unsigned char baudDivisor : 1;
	unsigned char transmitData;
	unsigned char receivedData;
	unsigned char URSELRegister : 1;
	unsigned char stopNum : 1;
	unsigned char polarity : 1;
	unsigned char polling : 1;
	unsigned long int UBRRRegister;
	
}
HardwareUsartConfig;


class HardwareUsart
{

	public:

	void setBaudDivisor(unsigned char flag);

	void setMultiProcessorCommunication(unsigned char flag);


	void setInterruptOnReceive(unsigned char flag);

	void setInterruptOnSend(unsigned char flag);

	void setInterruptOnDataEmpty(unsigned char flag);

	void setReceiver(unsigned char flag);

	void setTransmitter(unsigned char flag);

	void setDataSize(unsigned char flag);


	void setURSEL_Register(unsigned char flag);

	void setAsyncMode();

	void setSyncMode();

	void setParity(unsigned char flag);



	void setStopBit(unsigned char flag);

	void setPolarity(unsigned char flag);

	double setBaudRate(unsigned long rate); //returns the error for the given baud rate after it is set.
	void setUBRR(unsigned long int flag);

	unsigned long getClosestBaudRate(unsigned long rate);

	static unsigned long getClosestUBRR(unsigned long baud);

	void setCurrentFrequency(unsigned long int freq);

	void configureHardware();


	
	public:
	unsigned char getReceiveCompleteFlag();
	unsigned char getTransmitCompleteFlag();
	unsigned char getEmptyFlag();

	
		HardwareUsartConfig config;
		HardwareUsart();
		HardwareUsart(HardwareUsartConfig& c);
		void set(unsigned char data);
		unsigned char get();
		void run(); //for polling solutions.
		bool getFinished();
	unsigned char getReceivedData();

	void setTransmitData(unsigned char data);



};


#endif

